/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hirt;

import java.nio.ByteBuffer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author zamille
 */
public class ScenarioDataAction extends Action
{
    String scenarioName;
    String description;


    public ScenarioDataAction(String newName) {
        super();
        this.scenarioName = newName;
        description = "";
        super.messageType = Message.SCENARIO_DATA_MESSAGE;
    }

    public ScenarioDataAction(String newName, String description) {
        super();
        this.scenarioName = newName;
        this.description = description;
    }

    public ScenarioDataAction(ByteBuffer bytes, Vector<Item> items) {
        fromBytes(bytes, items);
        super.messageType = Message.SCENARIO_DATA_MESSAGE;
    }

    @Override
    protected ByteBuffer fromBytes(ByteBuffer bytes, Vector<Item> items)
    {
        ByteBuffer buf = super.fromBytes(bytes, items);
        scenarioName = ByteChanger.getString(buf, 0);
        description = ByteChanger.getString(buf, scenarioName.length()+4);
        try {
            buf = ByteChanger.truncate(buf, scenarioName.length()+description.length()+8);
        } catch (Exception ex) {
            
        }
        return buf;
    }


    public String getName() {
        return scenarioName;
    }

    public String getDescription() {
        return description;
    }

    public void setScenarioName(String newState) {
        this.scenarioName = newState;
    }

    @Override
    public ByteBuffer toByte()
    {
        ByteBuffer buf = super.toByte();
        //buf.putInt(scenarioName.length());
        //buf.put(scenarioName.getBytes());
        buf.putInt(scenarioName.length());
        buf.put(ByteChanger.stringToByte(scenarioName));
        buf.putInt(description.length());
        buf.put(ByteChanger.stringToByte(description));
        return buf;
    }


}
